﻿using System;
using Jet.Dal.EF.Implementation;
using Jet.Dal.EF.Tests.DataObjects;
using NUnit.Framework;

namespace Jet.Dal.EF.Tests
{
	[TestFixture]
	public class EFUnitOfWorkFactoryTests
	{
		[Test]
		public void TestCtor()
		{
			var factory = new EFUnitOfWorkFactory(Constants.ConnectionString);
			Assert.IsNotNull(factory);
			Assert.That(() => new EFUnitOfWorkFactory(null), Throws.TypeOf<ArgumentNullException>());
			Assert.That(() => new EFUnitOfWorkFactory(String.Empty), Throws.TypeOf<ArgumentNullException>());
		}

		[Test]
		public void TestCreate1Param()
		{
			var factory = new EFUnitOfWorkFactory(Constants.ConnectionString);
			var uow = factory.CreateUoW<Customer>(true, true);
			Assert.IsNotNull(uow.GetRepository<Customer>());
		}

		[Test]
		public void TestCreate2Param()
		{
			var factory = new EFUnitOfWorkFactory(Constants.ConnectionString);
			var uow = factory.CreateUoW<Customer, Order>(true, true);
			Assert.IsNotNull(uow.GetRepository<Customer>());
			Assert.IsNotNull(uow.GetRepository<Order>());
		}

		[Test]
		public void TestCreate3Param()
		{
			var factory = new EFUnitOfWorkFactory(Constants.ConnectionString);
			var uow = factory.CreateUoW<Customer, Order, Categories>(true, true);
			Assert.IsNotNull(uow.GetRepository<Customer>());
			Assert.IsNotNull(uow.GetRepository<Order>());
			Assert.IsNotNull(uow.GetRepository<Categories>());
		}

		[Test]
		public void TestCreate4Param()
		{
			var factory = new EFUnitOfWorkFactory(Constants.ConnectionString);
			var uow = factory.CreateUoW<Customer, Order, Categories, CustomerCustomerDemo>(true, true);
			Assert.IsNotNull(uow.GetRepository<Customer>());
			Assert.IsNotNull(uow.GetRepository<Order>());
			Assert.IsNotNull(uow.GetRepository<Categories>());
			Assert.IsNotNull(uow.GetRepository<CustomerCustomerDemo>());
		}

		[Test]
		public void TestCreate5Param()
		{
			var factory = new EFUnitOfWorkFactory(Constants.ConnectionString);
			var uow = factory.CreateUoW<Customer, Order, Categories, CustomerCustomerDemo,
				CustomerDemographics>(true, true);
			Assert.IsNotNull(uow.GetRepository<Customer>());
			Assert.IsNotNull(uow.GetRepository<Order>());
			Assert.IsNotNull(uow.GetRepository<Categories>());
			Assert.IsNotNull(uow.GetRepository<CustomerCustomerDemo>());
			Assert.IsNotNull(uow.GetRepository<CustomerDemographics>());
		}


		[Test]
		public void TestCreate6Param()
		{
			var factory = new EFUnitOfWorkFactory(Constants.ConnectionString);
			var uow = factory.CreateUoW<Customer, Order, Categories, CustomerCustomerDemo,
				CustomerDemographics, Employee>(true, true);
			Assert.IsNotNull(uow.GetRepository<Customer>());
			Assert.IsNotNull(uow.GetRepository<Order>());
			Assert.IsNotNull(uow.GetRepository<Categories>());
			Assert.IsNotNull(uow.GetRepository<CustomerCustomerDemo>());
			Assert.IsNotNull(uow.GetRepository<CustomerDemographics>());
			Assert.IsNotNull(uow.GetRepository<Employee>());
		}

		[Test]
		public void TestCreate7Param()
		{
			var factory = new EFUnitOfWorkFactory(Constants.ConnectionString);
			var uow = factory.CreateUoW<Customer, Order, Categories, CustomerCustomerDemo,
				CustomerDemographics, Employee, EmployeeTerritories>(true, true);
			Assert.IsNotNull(uow.GetRepository<Customer>());
			Assert.IsNotNull(uow.GetRepository<Order>());
			Assert.IsNotNull(uow.GetRepository<Categories>());
			Assert.IsNotNull(uow.GetRepository<CustomerCustomerDemo>());
			Assert.IsNotNull(uow.GetRepository<CustomerDemographics>());
			Assert.IsNotNull(uow.GetRepository<Employee>());
			Assert.IsNotNull(uow.GetRepository<EmployeeTerritories>());
		}

		[Test]
		public void TestCreate8Param()
		{
			var factory = new EFUnitOfWorkFactory(Constants.ConnectionString);
			var uow = factory.CreateUoW<Customer, Order, Categories, CustomerCustomerDemo,
				CustomerDemographics, Employee, EmployeeTerritories, OrderDetails>(true, true);
			Assert.IsNotNull(uow.GetRepository<Customer>());
			Assert.IsNotNull(uow.GetRepository<Order>());
			Assert.IsNotNull(uow.GetRepository<Categories>());
			Assert.IsNotNull(uow.GetRepository<CustomerCustomerDemo>());
			Assert.IsNotNull(uow.GetRepository<CustomerDemographics>());
			Assert.IsNotNull(uow.GetRepository<Employee>());
			Assert.IsNotNull(uow.GetRepository<EmployeeTerritories>());
			Assert.IsNotNull(uow.GetRepository<OrderDetails>());
		}

		[Test]
		public void TestCreate9Param()
		{
			var factory = new EFUnitOfWorkFactory(Constants.ConnectionString);
			var uow = factory.CreateUoW<Customer, Order, Categories, CustomerCustomerDemo,
				CustomerDemographics, Employee, EmployeeTerritories, OrderDetails, Products>(true, true);
			Assert.IsNotNull(uow.GetRepository<Customer>());
			Assert.IsNotNull(uow.GetRepository<Order>());
			Assert.IsNotNull(uow.GetRepository<Categories>());
			Assert.IsNotNull(uow.GetRepository<CustomerCustomerDemo>());
			Assert.IsNotNull(uow.GetRepository<CustomerDemographics>());
			Assert.IsNotNull(uow.GetRepository<Employee>());
			Assert.IsNotNull(uow.GetRepository<EmployeeTerritories>());
			Assert.IsNotNull(uow.GetRepository<OrderDetails>());
			Assert.IsNotNull(uow.GetRepository<Products>());
		}

		[Test]
		public void TestCreate10Param()
		{
			var factory = new EFUnitOfWorkFactory(Constants.ConnectionString);
			var uow = factory.CreateUoW<Customer, Order, Categories, CustomerCustomerDemo,
				CustomerDemographics, Employee, EmployeeTerritories, OrderDetails, Products, Region>(true, true);
			Assert.IsNotNull(uow.GetRepository<Customer>());
			Assert.IsNotNull(uow.GetRepository<Order>());
			Assert.IsNotNull(uow.GetRepository<Categories>());
			Assert.IsNotNull(uow.GetRepository<CustomerCustomerDemo>());
			Assert.IsNotNull(uow.GetRepository<CustomerDemographics>());
			Assert.IsNotNull(uow.GetRepository<Employee>());
			Assert.IsNotNull(uow.GetRepository<EmployeeTerritories>());
			Assert.IsNotNull(uow.GetRepository<OrderDetails>());
			Assert.IsNotNull(uow.GetRepository<Products>());
			Assert.IsNotNull(uow.GetRepository<Region>());
		}

		[Test]
		public void TestCreate11Param()
		{
			var factory = new EFUnitOfWorkFactory(Constants.ConnectionString);
			var uow = factory.CreateUoW<Customer, Order, Categories, CustomerCustomerDemo,
				CustomerDemographics, Employee, EmployeeTerritories, OrderDetails, Products, Region, Shipper>(true, true);
			Assert.IsNotNull(uow.GetRepository<Customer>());
			Assert.IsNotNull(uow.GetRepository<Order>());
			Assert.IsNotNull(uow.GetRepository<Categories>());
			Assert.IsNotNull(uow.GetRepository<CustomerCustomerDemo>());
			Assert.IsNotNull(uow.GetRepository<CustomerDemographics>());
			Assert.IsNotNull(uow.GetRepository<Employee>());
			Assert.IsNotNull(uow.GetRepository<EmployeeTerritories>());
			Assert.IsNotNull(uow.GetRepository<OrderDetails>());
			Assert.IsNotNull(uow.GetRepository<Products>());
			Assert.IsNotNull(uow.GetRepository<Region>());
			Assert.IsNotNull(uow.GetRepository<Shipper>());
		}

		[Test]
		public void TestCreate12Param()
		{
			var factory = new EFUnitOfWorkFactory(Constants.ConnectionString);
			var uow = factory.CreateUoW<Customer, Order, Categories, CustomerCustomerDemo,
				CustomerDemographics, Employee, EmployeeTerritories, OrderDetails, Products,
				Region, Shipper, Suppliers>(true, true);
			Assert.IsNotNull(uow.GetRepository<Customer>());
			Assert.IsNotNull(uow.GetRepository<Order>());
			Assert.IsNotNull(uow.GetRepository<Categories>());
			Assert.IsNotNull(uow.GetRepository<CustomerCustomerDemo>());
			Assert.IsNotNull(uow.GetRepository<CustomerDemographics>());
			Assert.IsNotNull(uow.GetRepository<Employee>());
			Assert.IsNotNull(uow.GetRepository<EmployeeTerritories>());
			Assert.IsNotNull(uow.GetRepository<OrderDetails>());
			Assert.IsNotNull(uow.GetRepository<Products>());
			Assert.IsNotNull(uow.GetRepository<Region>());
			Assert.IsNotNull(uow.GetRepository<Shipper>());
			Assert.IsNotNull(uow.GetRepository<Suppliers>());
		}
	}
}
